home *** CD-ROM | disk | FTP | other *** search
Text File | 1989-11-20 | 6.6 KB | 313 lines | [TEXT/MPS ] |
- /*
- * SpinAbout by Andrew Shebanow 10/31/89 (Boo!)
- *
- * About box XCMD for Spin stack.
- * Displays a picture as a backdrop in a window,
- * and animates a list of names over the top
- */
-
- #include <string.h>
- #include <stddef.h>
-
- #include <Types.h>
- #include <Strings.h>
- #include <QuickDraw.h>
- #include <Fonts.h>
- #include <Events.h>
- #include <Controls.h>
- #include <Windows.h>
- #include <Menus.h>
- #include <TextEdit.h>
- #include <Dialogs.h>
- #include <Desk.h>
- #include <Scrap.h>
- #include <ToolUtils.h>
- #include <Memory.h>
- #include <Resources.h>
- #include <SegLoad.h>
- #include <Files.h>
- #include <OSUtils.h>
- #include <OSEvents.h>
- #include <DiskInit.h>
- #include <Packages.h>
-
- #include <HyperXCMD.h>
-
- const short kColorPictID = 20000;
- const short kBWPictID = 20001;
- const short kStringsID = 20000;
-
- class TSpinAbout {
- private:
- XCmdPtr fParamPtr;
- GrafPtr fSavePort;
- PicHandle fPicture;
- Rect fWindRect;
- Rect fPictRect;
- WindowPtr fWindow;
- short fTextVOffset;
- short fStringIdx;
- long fLastTicks;
- BitMap* fScreenBits;
- Str255 fCreditString;
- Boolean fDone;
- Boolean fHaveColorQD;
- Boolean fHaveColorScreen;
-
- public:
- TSpinAbout(XCmdPtr paramPtr);
- ~TSpinAbout();
-
- void DoSpinAbout();
-
- void GetPicture();
- void CreateWindow();
- void GetCreditString();
- void DrawCredits();
-
- // utility routines
- void SetReturnString(char* str);
- void ErrAbort(char* str);
- void CheckQDEnvironment();
-
- // Do nothing routine to fake out compiler
- void DoNothing(char* str);
- };
-
- pascal void EntryPoint(XCmdPtr paramPtr)
- {
- TSpinAbout theSpinAbout(paramPtr);
-
- theSpinAbout.DoSpinAbout();
- }
-
- TSpinAbout::TSpinAbout(XCmdPtr paramPtr)
- {
- // get current port - always our card window
- GetPort(&fSavePort);
-
- // save off XCMDPtr for use by other methods
- fParamPtr = paramPtr;
-
- fDone = false;
- fPicture = nil;
- fWindow = nil;
- fStringIdx = 1;
- fLastTicks = 0;
- fCreditString[0] = '\0';
-
- if (fDone)
- DoNothing("SpinAbout by Andrew Shebanow © Copyright 1989 Apple Computer. All Rights Reserved.");
-
- /* Set the cursor to the arrow for use with the dialog box. */
- InitCursor();
- /* Flush all events to be safe. */
- FlushEvents(everyEvent,0);
-
- CheckQDEnvironment();
- }
-
- TSpinAbout::~TSpinAbout()
- {
- // clean up and exit
- if (fWindow)
- DisposeWindow(fWindow);
- if (fPicture)
- ReleaseResource((Handle)fPicture);
-
- /* Flush all events to be safe. */
- FlushEvents(everyEvent,0);
-
- /*
- Let HyperCard set the cursor to a known state, so the next "idle" message
- after the dialog goes away will reset it to the correct cursor. (HyperCard
- doesn't know we did an InitCursor.)
- */
- SendHCMessage(fParamPtr,"\pset cursor to 4"); /* 4 = the watch cursor */
-
- // restore saved port
- SetPort(fSavePort);
- }
-
- void TSpinAbout::DoSpinAbout()
- {
- // read in the apropos picture
- GetPicture();
- if (fDone) return; // check for errors
-
- // create the window
- CreateWindow();
- if (fDone) return; // check for errors
-
- GetCreditString();
- DrawCredits();
- fLastTicks = TickCount();
-
- while (!fDone)
- {
- // get next event
- EventRecord evtRec;
- SystemTask();
- Boolean gotEvent = GetNextEvent(everyEvent,&evtRec);
-
- if (gotEvent)
- switch (evtRec.what)
- {
- case mouseDown:
- (void) p2cstr(fCreditString);
- SetReturnString((char*) fCreditString);
- (void) c2pstr((char*) fCreditString);
- fDone = true;
- break;
- case updateEvt:
- WindowPtr wind = (WindowPtr) evtRec.message;
- if (wind == fWindow)
- {
- SetPort(wind);
- BeginUpdate(wind);
- DrawCredits();
- EndUpdate(wind);
- }
- break;
- default:
- break;
- }
-
- // check if it is time for another string to show up
- long curTicks = TickCount();
- if ((curTicks - fLastTicks) >= 90)
- {
- fLastTicks = curTicks;
- GetCreditString();
- DrawCredits();
- }
- }
- }
-
- void TSpinAbout::GetPicture()
- {
- short pictResID = kBWPictID;
- if (fHaveColorScreen)
- pictResID = kColorPictID;
-
- // get PICT resource
- fPicture = (PicHandle) GetResource('PICT',pictResID);
- if (fPicture == nil)
- {
- if (fHaveColorScreen)
- {
- // couldn't read in mondo color pict, so try for BW
- fPicture = (PicHandle) GetResource('PICT',kBWPictID);
- if (fPicture == nil)
- {
- ErrAbort("Not enough memory to read picture.");
- return;
- }
- }
- else
- {
- ErrAbort("Not enough memory to read picture.");
- return;
- }
- }
- HNoPurge((Handle) fPicture);
- }
-
- void TSpinAbout::CreateWindow()
- {
- // get rect of picture
- fWindRect = (*fPicture)->picFrame;
-
- // center it on screen
- OffsetRect(&fWindRect,-fWindRect.left,-fWindRect.top);
- short offH = (fScreenBits->bounds.right - fScreenBits->bounds.left - fWindRect.right) / 2;
- short offV = (fScreenBits->bounds.bottom - fScreenBits->bounds.top - fWindRect.bottom) / 2;
- OffsetRect(&fWindRect,offH,offV);
-
- // create window (in color if available)
- if (fHaveColorQD)
- fWindow = NewCWindow(nil,&fWindRect,"\p",true,dBoxProc,(WindowPtr)-1,false,0);
- else fWindow = NewWindow(nil,&fWindRect,"\p",true,dBoxProc,(WindowPtr)-1,false,0);
- if (fWindow == nil)
- {
- ErrAbort("Not enough memory to allocate window.");
- return;
- }
-
- // make the window the current port
- SetPort(fWindow);
-
- // set up pict rect to be size of window's content region
- fPictRect = fWindow->portRect;
-
- // preprepare font
- TextFont(helvetica);
- TextSize(14);
- TextFace(bold);
-
- // figure out where to draw text (vertically), leave
- // room for text above centerline
- fTextVOffset = ((fPictRect.bottom - fPictRect.top) / 2) + 20;
- }
-
- void TSpinAbout::GetCreditString()
- {
- GetIndString(fCreditString,kStringsID,fStringIdx);
- if (Length(fCreditString) == 0)
- fStringIdx = 1; // set up to start all over
- else fStringIdx++;
- }
-
- void TSpinAbout::DrawCredits()
- {
- DrawPicture(fPicture,&fPictRect);
-
- short tWidth = StringWidth(fCreditString);
- short dh = (fPictRect.right - fPictRect.left - tWidth) / 2;
- MoveTo(fPictRect.left + dh, fTextVOffset);
- DrawString(fCreditString);
- }
-
- void TSpinAbout::SetReturnString(char *str)
- {
- Handle nuHndl;
-
- nuHndl = NewHandle((long)(strlen(str)+1));
- if (nuHndl == nil) return;
- strcpy((char *)*nuHndl,str);
- fParamPtr->returnValue = nuHndl;
- }
-
- void TSpinAbout::ErrAbort(char *str)
- {
- SetReturnString(str);
- fDone = true;
- }
-
- void TSpinAbout::CheckQDEnvironment()
- {
- SysEnvRec env;
-
- fHaveColorScreen = false;
-
- // do we have color QD? (ask SysEnvirons)
- (void) SysEnvirons(curSysEnvVers,&env);
- fHaveColorQD = env.hasColorQD;
-
- // do we have a color screen to draw on?
- if (fHaveColorQD)
- {
- GDHandle gd = GetMainDevice();
- if ((*(*gd)->gdPMap)->pixelSize > 1)
- fHaveColorScreen = true;
- }
-
- // get coordinates of screen
- long* thePortPtr = (long*) SetCurrentA5();
- fScreenBits = (BitMap*) (*thePortPtr - 122);
- }
-
- void TSpinAbout::DoNothing(char* str)
- {
- }
-